<?php

namespace App\Models\Admin;

use App\Models\Panx\Product;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * @property int name
 * @property int id
 * @property mixed sort
 *
 * @method static self filterCustomer(int $customer_id)
 *
 * @mixin Builder
 */
class CosmeticMaterial extends Model
{
    protected $table = 'cosmetic_materials';
    protected $guarded = [];

    protected $casts = [
        'sort' => 'int'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function products()
    {
        return $this->hasMany(Product::class, 'cosmetic_material_id', 'id');
    }

    /**
     * @used-by filterCustomer()
     *
     * @param Builder $query
     * @param $customer_id
     * @return Builder
     */
    public function scopeFilterCustomer(Builder $query, int $customer_id)
    {
        return $query->where('customer_id', $customer_id);
    }
}
